<template>
  <div class="root">
    <p>两个时间格式化的方法都是为了格式化成标准时间</p>
    <pre>
      <code>
        export function formatDate (time, fmt) {
          let date = new Date(time);
          let y = date.getFullYear();
          let MM = date.getMonth() + 1;
          MM = MM < 10 ? ('0' + MM) : MM;
          let d = date.getDate();
          d = d < 10 ? ('0' + d) : d;
          let h = date.getHours();
          h = h < 10 ? ('0' + h) : h;
          let m = date.getMinutes();
          m = m < 10 ? ('0' + m) : m;
          let s = date.getSeconds();
          s = s < 10 ? ('0' + s) : s;
          let str = fmt.split('-');
          let res = '';
          for (let i in str) {
            if(str[i] == 'yyyy'){
              res = y;
            }else if(str[i] == 'mm') {
              if(res == '') {
                res =  MM;
              }else {
                res = res +'-' + MM;
              }
            }else if(str[i] == 'dd') {
              if(res == '') {
                res =  d;
              }else {
                res = res +'-' + d;
              }
            }else if(str[i] == 'h') {
              if(res == '') {
                res =  h;
              }else {
                res = res +'-' + h;
              }
            }else if(str[i] == 'm') {
              if(res == '') {
                res =  m;
              }else {
                res = res +':' + m;
              }
            }else if(str[i] == 's') {
              if(res == '') {
                res =  s;
              }else {
                res = res +':' + s;
              }
            }
          }
          return res;
        }
        
        getDate() {
          var second = this.details.addition_card.over_sec;  // 获取的已经是剩余时间
          var day = Math.floor(second / 86400);//整数部分代表的是天；一天有24*60*60=86400秒 ；
          second = second % 86400;//余数代表剩下的秒数；
          var hour = Math.floor(second / 3600);//整数部分代表小时；
          second %= 3600; //余数代表 剩下的秒数；
          var minute = Math.floor(second / 60);
          second %= 60;
          let str = day + '天' + this.tow(hour) + '小时' + this.tow(minute) + '分钟' + this.tow(second) + '秒';
          this.lastTime = str;
        }
        tow(n) {
          return n >= 0 && n < 10 ? '0' + n : '' + n;
        }
      </code>
    </pre>
  </div>
</template>

<script>
  export default {
    components: {},

    data() {
      return {
        
      };
    },

    created() {},

    mounted() {},

    methods: {
      
    }
  };
</script>
<style lang="less" scoped>
  
</style>
